home *** CD-ROM | disk | FTP | other *** search
/ The Fatted Calf / The Fatted Calf.iso / Applications / Graphics / GraphicsWorkshop / Source / Examples / gwcopy / Converter.h < prev    next >
Encoding:
Text File  |  1992-02-01  |  7.0 KB  |  173 lines

  1. /*
  2.  * This is perhaps one of the most important objects. It's what deals with reading and
  3.  * writing the bitmaps to and from disk. When used init and free should always be called.
  4.  * The concept of sender is used in a couple of places in this object and should respond to
  5.  * the following request: It should respond to getImageCon and return the id of a ImageControl 
  6.  * object. Note that the NXBitmapImageRep links this from disk at run time. You may also
  7.  * do this, should you wish, or you may define your own set of internal routines. Whatever
  8.  * you do, the ImageControl object should respond to everything defined in image.h, and
  9.  * these should have predictable results.
  10.  */
  11.  
  12. #import <objc/Object.h>
  13.  
  14. #define CONVERT_ERR_NONE        0
  15. #define CONVERT_ERR_WARNING    1
  16. #define CONVERT_ERR_FATAL        2
  17.  
  18. #define ERROR_NO_ERROR            0
  19. #define ERROR_UNABLE_TO_OPEN    1
  20. #define ERROR_PERMISSION_DENIED    2
  21. #define ERROR_BAD_FORMAT        3
  22. #define ERROR_TRUNCATED_FILE    4
  23.  
  24. @interface Converter : Object
  25. {
  26.     int        errState;
  27. }
  28.  
  29. /*
  30.  * Initializes the object. This need not necessarily be used, but you can use it if you'd like.
  31.  * Assumes:     Nothing
  32.  * Returns:    self
  33.  * Results:    A new object is up and running.
  34.  */
  35. - init;
  36.  
  37. /*
  38.  * Frees anything used by the object.
  39.  * Assumes:    Object is instantiated.
  40.  * Results:     It is no longer valid to message the object.
  41.  */
  42. - free;
  43.  
  44. /*
  45.  * Reads the bitmap from stream. 
  46.  * Assumes:    The object has been instantiates, stream is an valid stream opened for at least
  47.  *            reading. Sender is the id of whatever object is calling the converter. 
  48.  * Returns:    id of an NXBitmapImageRep or nil if the image was unable to be read.
  49.  */
  50. - readFromStream: (NXStream *)stream from: sender;
  51.  
  52. /*
  53.  * Write the bitmaps id to stream.
  54.  * Assumes:    Object has been instantiated. At times, it's best to have used a call to the
  55.  *             save panel first, since this can set internal variables, but it's not necessary.
  56.  *            stream should be a valid NXStream opened for at least writing. Sender should
  57.  *            be the id of the caller. id is a NXBitmapImageRep, or something that responds
  58.  *            to all the message of the NXBitmapImageRep.
  59.  * Returns:    YES if the image was sucessfully writing, otherwise it returns NO.
  60.  */
  61. - (BOOL)write: (id)image toStream: (NXStream *)stream from: sender;
  62.  
  63. /*
  64.  * Similar to readFromStream but will read multiple images from a stream when present.
  65.  * Assumes:     Object instantiated. stream valid for reading. sender is id of caller.
  66.  * Returns:    id of an NXImage or nil if unable to read the image. It should return a single
  67.  *            image in the least, even for formats that don't support multiple images.
  68.  */
  69. - readAllFromStream: (NXStream *)stream from: sender;
  70.  
  71. /*
  72.  * Reverses the process of read all.
  73.  * Assumes:     Object instantiates. id is to an NXImage or something that responds to all of
  74.  *            NXImage's methods. stream is valid for writing. This should always attempt
  75.  *            to write at least one image to disk (the first usually) even for formats that 
  76.  *            don't support multiple images.
  77.  * Returns:    YES if the image is sucessfully written to disk.
  78.  */
  79. - (BOOL)writeAll: (id)image toStream: (NXStream *)stream;
  80.  
  81. /*
  82.  * Creates and lays out a custom view that the converter can use to set customization
  83.  * parameters. 
  84.  * Assumes:     Object instantiated and the window server is running. width should be the
  85.  *            maximum width the custom view can be.
  86.  * Returns:    id of a parent view or nil if this object doesn't use one.
  87.  */
  88. - customSaveView: (int)width;
  89.  
  90. /*
  91.  * This is very similar to customSaveView, however, it is used to set parameters for
  92.  * the run time loading of images. This object does not support input custom views.
  93.  * Assumes:     Object instantiated and the window server is running. width should be the
  94.  *            maximum width the custom view can be.
  95.  * Returns:    id of a parent view or nil if this object doesn't use one.
  96.  */
  97. - customOpenView: (int)width;
  98.  
  99. /*
  100.  * Returns the name of the current format, ie, the gif converter returns the string "Graphics
  101.  * Interchange Format (GIF)".
  102.  * Assumes:     Object has been instantiated.
  103.  * Returns:    A pointer to a string. The caller should always use something like strcpy to
  104.  *            get a copy of the string, since it's life is only guaranteed for the life of the
  105.  *            object.
  106.  */
  107. - (char *)getFormatName;
  108.  
  109. /*
  110.  * This is a simple interface to setting custom values of various parameters. There are
  111.  * no standards for what a converter must take of these values, so while the converter
  112.  * will tell you whether it took the value you or not, you, as the programmer, should
  113.  * not get upset when a parameter is not taken. Likewise, should the converter receive
  114.  * a request to set a parameter it does not understand, it should always refuse it with
  115.  * grace (ie, make it idiot proof.) What parameters an indivudual converter will take
  116.  * should be documented somewhere with the converters distribution.
  117.  * Assumes:    The converter is instantiated, parameter is a NULL terminated character
  118.  *            string, and ptr is a pointer to the data type. This is determined by patameter.
  119.  * Returns:    YES if the value was set, NO if the setting failed for any reason.
  120.  */
  121.  - (BOOL)setCustomParameter: (const char *)parameter withValue: (void *)ptr;
  122.  
  123. /*
  124.  * Gets a custom parameter value. See above about support for this call, as it's similar
  125.  * to setCustomParameter. Mainly, the converter should not crash when a request for
  126.  * a non-existant parameter is made.
  127.  * Assumes:     The converter is instantiated and parameter is a NULL terminater char-
  128.  *            acter string.
  129.  * Returns:    A pointer to the parameter (type depends on return value) or nil if the
  130.  *            parameter is not understood.
  131.  */
  132.  - (void *)getCustomParameter: (const char *)parameter;
  133.  
  134.  /*
  135.   * Returns a string with copyright information, name of the author, where the author
  136.   * can be reached, etc. This should only be a couple of lines, so keep it short and 
  137.   * sweet. An example might be:
  138.   * "My Image Format Converter\nby Joe Programmer\nCopyright R'N'R Software\n ...
  139.   * ... email bugs to jprogramm@system.there.edu"
  140.   * Assumes:     Converter linked and instantiated.
  141.   * Returns:    A pointer to a null terminated string. This string must be non volatile for
  142.   *             the life of the converter. Ie, as long as the programmer keeps a converter
  143.   *            linked, the pointer should be valid.
  144.   */
  145.  - (char *)copyrightNotice;
  146.  
  147.  /*
  148.   * Returns the current error state of the converter.
  149.   * Assumes:     Converter has been instantiated.
  150.   * Returns:    0 = CONVERT_ERR_NONE         Signals no error
  151.   *            1 = CONVERT_ERR_WARNING   Signals action taken, but not one expected.
  152.   *            2 = CONVERT_ERR_FATAL          Signals no action taken.
  153.   */
  154.  - (int)errorState;
  155.  
  156.  /*
  157.   * Returns an int describing the current error message.
  158.   * Assumes:    Converter instantiated.
  159.   * Returns:    An int describing the error type. See defines for integers returned.
  160.   */
  161.  - (int)errorMessage;
  162.  
  163. /*
  164.  * Returns a string in the form <major version>.<minor version>. This is used by 
  165.  * the calling program to see what level or protocol the object will respond to. 
  166.  * Assumes:    Converter instantiated.
  167.  * Returns:    A null terminated string in the form <major version>.<minor version>.
  168.  *            For example, 1.0.
  169.  */
  170. - (char *)protocolVersion;
  171.  
  172. @end
  173.